import java.util.*;

public class MobileUser {
	int moveCounter;
	int callCounter;
	int replicaCost;
	int fpCounter = 4;
	
	String id;
	Node currentCell;
	TransType currTransType;
	ArrayList<Node> replicaHolders;

	MobileUser(Node theParent, String theId){
		currentCell = theParent;
		this.id 	= theId;
		theParent.addUser(this);
		replicaHolders = new ArrayList<Node>();
		moveCounter = 0;
		replicaCost = 1;
		currTransType = TransType.ADDRESS;
		}
	public String getId()
	{
		return id;
	}
	public void changeTransType(TransType newTransType)
	{
		currTransType = newTransType;
		
	}
	public void move(Node DestCell){
		
		if((!DestCell.lookUp.containsKey(currentCell))&&(currTransType.name()=="FOREWARD")&&(fpCounter>=0))
		{
			fpCounter--;
			currentCell.lookUp.remove(this);
			currentCell.lookUp.put(DestCell,this);
			currentCell.activate();
			DestCell.activate();
		}
		else if((!DestCell.lookUp.containsKey(currentCell))&&(currTransType.name()=="FOREWARD")&&(fpCounter == 0))
		{
			fpCounter =4;
			currentCell.updateLookUp(currentCell, DestCell, this);
		}
		else
		{
			currentCell.updateLookUp(currentCell, DestCell, this);
		}
			
	}
	
	public void move(int DestCellID)
	{
		moveCounter ++;
		currentCell.MoveUser(this,DestCellID);
		for(int i = 0; i < replicaHolders.size(); i++)
		{
			replicaHolders.get(i).updateReplica(this.getId(),DestCellID);
		}
	}
	public int getReplicaCost()
	{
		return replicaCost;
	}
	public int getMoveCounter()
	{
		return moveCounter;
	}
	public void sendCall(String Destination)
	{
		if(currTransType == TransType.REPLICATION)
		{	
		currentCell.callReplica(Destination);
			
		}
		else
		currentCell.callSearchCA(Destination);
		
	}
	public Node getLocation()
	{
		return currentCell;
		
	}
	public void setLocation(Node Cell)
	{
		this.currentCell = Cell;
	}
	public void addReplicaHolder(Node holder)
	{
		replicaHolders.add(holder);
		replicaCost++;
	}
 }
